import request from '@/utils/request'

/**
 * 获取结算信息
 * @param {}
 * @return {}
 */
export const createOrder = () => {
  return request('/member/order/pre', 'get')
}

/**
 * 添加收货地址信息
 * @param {Object} address - 地址对象
 * @return {}
 */

export const addAddress = (address) => {
  return request('/member/address', 'post', address)
}

/**
 * 获取收货地址列表
 * @return {}
 */

export const findAddressList = () => {
  return request('/member/address', 'get')
}

/**
 * 编辑收货地址信息
 * @param {Object} address - 地址对象
 * @return {}
 */
export const editAddress = (form) => {
  return request(`/member/address/${form.id}`, 'put', form)
}

/**
 * 结算页面-提交订单
 * @param {Object} order - 订单信息对象
 * @return {}
 */
export const submitCheckInfo = (order) => {
  return request('/member/order', 'post', order)
}

/**
 * 获取订单详情
 * @param {string} id - 订单ID
 * @return {}
 */
export const findOrderDetail = (id) => {
  return request('/member/order/' + id, 'get')
}

/**
 * 查询订单列表
 * @param {Number} orderState - 订单状态
 * @param {Number} page - 页码
 * @param {Number} pageSize - 每页条数
 * @return {}
 */
export const findOrderList = ({ page, pageSize, orderState }) => {
  return request('/member/order', 'get', { page, pageSize, orderState })
}

/**
 * 取消订单
 * @param {String} orderId - 订单id
 * @param {String} cancelReason - 取消原因
 * @return promise
 */
export const cancelOrder = (orderId, cancelReason) => {
  return request(`/member/order/${orderId}/cancel`, 'put', { cancelReason })
}

/**
 * 删除订单
 * @param {Array<String>} ids - 删除订单，ID集合
 * @return {}
 */

export const deleteOrder = (ids) => {
  return request('/member/order', 'delete', { ids })
}

/**
 * 确认收货
 * @param {String} orderId - 订单ID
 * @returns
 */
export const confirmOrder = (orderId) => {
  return request(`/member/order/${orderId}/receipt`, 'put')
}

/**
 * 查看物流
 * @param {String} orderId - 订单ID
 * @returns
 */

export const logisticsOrder = (id) => {
  return request('/member/order/1670459873701265410/logistics', 'get')
  // return request(`/member/order/${id}/logistics`, 'get')
}

/**
 * 获取再次购买的订单结算信息 - 再次购买
 * @param {String}  id - 订单id
 * @return {}
 */
export const findOrderRepurchase = (id) => {
  return request(`/member/order/repurchase/${id}`, 'get')
}
